package com.globalwave.virgin.drools;

import java.io.InputStreamReader;
import java.io.Reader;

import org.drools.compiler.compiler.PackageBuilder;
import org.drools.core.RuleBase;
import org.drools.core.RuleBaseFactory;
import org.drools.core.WorkingMemory;
import org.junit.Test;


public class HelloWorld {

	@Test
	public void test() throws Exception {
		   //read in the source
		   Reader source = new InputStreamReader( this.getClass().getResourceAsStream( "/Rule.drl" ) );

		   //Use package builder to build up a rule package.
		  PackageBuilder builder = new PackageBuilder();
		  //this wil parse and compile in one step
		   builder.addPackageFromDrl( source );

		   //get the compiled package (which is serializable)
		   org.drools.core.rule.Package pkg = builder.getPackage();
		  //add the package to a rulebase (deploy the rule package).
		   RuleBase ruleBase = RuleBaseFactory.newRuleBase();
		   ruleBase.addPackage( pkg );
		   WorkingMemory workingMemory = ruleBase.newStatefulSession();
		   Message message = new Message();
		   message.setMessage( "Hello World" );
		   message.setStatus( Message.HELLO );
		   workingMemory.insert(message);
		   workingMemory.fireAllRules();

	}
	
	public class Message{
		private String message ;
		private String Status ;
	}
}
